USE [genshi]
GO

/****** Object:  Trigger [dbo].[Relics_down]    Script Date: 2022/5/3 20:28:17 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TRIGGER [dbo].[Relics_down] ON [dbo].[Assemble]
AFTER UPDATE
AS
Begin
	SET NOCOUNT ON;
	Declare @idflower smallint;
	Declare @idfeather smallint;
	Declare @idsand smallint;
	Declare @idcup smallint;
	Declare @idhead smallint;
	Declare @id smallint;
	Declare @Name nvarchar(10);
	select @Name = inserted.Name from inserted;

	/*一次只能卸掉一个圣遗物，所以仅有一个id是非空值*/
	select @idflower = deleted.Flower
	from deleted
	where deleted.Flower is not null AND exists(select * from inserted where inserted.Name = deleted.Name AND inserted.Flower is null);

	select @idfeather = deleted.Feather
	from deleted
	where deleted.Feather is not null AND exists(select * from inserted where inserted.Name = deleted.Name AND inserted.Feather is null);

	select @idsand = deleted.Sand
	from deleted
	where deleted.Sand is not null AND exists(select * from inserted where inserted.Name = deleted.Name AND inserted.Sand is null);

	select @idcup = deleted.Cup
	from deleted
	where deleted.Cup is not null AND exists(select * from inserted where inserted.Name = deleted.Name AND inserted.Cup is null);

	select @idhead = deleted.Head
	from deleted
	where deleted.Head is not null AND exists(select * from inserted where inserted.Name = deleted.Name AND inserted.Head is null);

	/*得到被卸掉圣遗物的id*/
	if (@idflower is not null)
		begin
			set @id = @idflower;
		end
	else if (@idfeather is not null)
		begin
			set @id = @idfeather;
		end
	else if (@idsand is not null)
		begin
			set @id = @idsand;
		end
	else if (@idcup is not null)
		begin
			set @id = @idcup;
		end
	else if (@idhead is not null)
		begin
			set @id = @idhead;
		end

	/*删掉id号*/
	UPDATE Relics
	set equipped = null
	where id = @id;

	Declare @mainTagname nvarchar(19);
	Declare @Tagname_1 nvarchar(19);
	Declare @Tagname_2 nvarchar(19);
	Declare @Tagname_3 nvarchar(19);
	Declare @Tagname_4 nvarchar(19);
	Declare @mainTagvalue real;
	Declare @value_1 real;
	Declare @value_2 real;
	Declare @value_3 real;
	Declare @value_4 real;

	/*仅当有圣遗物被卸载时执行*/
	if (@id is not null)
		begin
			select @mainTagname = mainTagname,@Tagname_1 = Tagname_1, @Tagname_2= Tagname_2 ,@Tagname_3 = Tagname_3,@Tagname_4 = Tagname_4,
			@mainTagvalue = mainTagvalue,@value_1 = value_1,@value_2 = value_2,@value_3 = value_3,@value_4 = value_4
			from Relics where @id = Relics.id;	

			/*删去主词条属性值*/
			if(@mainTagname = '生命值')
				begin
					update Assemble
					set Assemble.IncreaseLife = Assemble.IncreaseLife - @mainTagvalue
					where Assemble.Name = @Name;
				end
			else if(@mainTagname = '攻击力')
				begin
					update Assemble
					set Assemble.IncreaseAttack = Assemble.IncreaseAttack - @mainTagvalue
					where Assemble.Name = @Name;					
				end
			else if (@mainTagname = '攻击力百分比')
				begin
					update Assemble
					set Assemble.AttackPercentage = Assemble.AttackPercentage - @mainTagvalue
					where Assemble.Name = @Name;	
				end
			else if(@mainTagname = '生命值百分比')
				begin
					update Assemble
					set Assemble.LifePercentage = Assemble.LifePercentage - @mainTagvalue
					where Assemble.Name = @Name;	
				end
			else if(@mainTagname = '防御力百分比')
				begin
					update Assemble
					set Assemble.DefensePercentage = Assemble.DefensePercentage - @mainTagvalue
					where Assemble.Name = @Name;	
				end
			else if(@mainTagname = '元素精通')
				begin
					update Assemble
					set Assemble.Mystery = Assemble.Mystery - @mainTagvalue
					where Assemble.Name = @Name;	
				end
			else if(@mainTagname = '元素充能效率')
				begin
					update Assemble
					set Assemble.Efficiency = Assemble.Efficiency - @mainTagvalue
					where Assemble.Name = @Name;	
				end
			else if(@mainTagname = '火元素伤害加成')
				begin
					update Assemble
					set Assemble.Fire = Assemble.Fire - @mainTagvalue
					where Assemble.Name = @Name;	
				end
			else if(@mainTagname = '水元素伤害加成')
				begin
					update Assemble
					set Assemble.Water = Assemble.Water - @mainTagvalue
					where Assemble.Name = @Name;	
				end
			else if(@mainTagname = '雷元素伤害加成')
				begin
					update Assemble
					set Assemble.Thunder = Assemble.Thunder - @mainTagvalue
					where Assemble.Name = @Name;	
				end
			else if(@mainTagname = '风元素伤害加成')
				begin
					update Assemble
					set Assemble.Wind = Assemble.Wind - @mainTagvalue
					where Assemble.Name = @Name;	
				end
			else if(@mainTagname = '冰元素伤害加成')
				begin
					update Assemble
					set Assemble.Ice = Assemble.Ice - @mainTagvalue
					where Assemble.Name = @Name;	
				end
			else if(@mainTagname = '岩元素伤害加成')
				begin
					update Assemble
					set Assemble.Rock = Assemble.Rock - @mainTagvalue
					where Assemble.Name = @Name;	
				end
			else if(@mainTagname = '物理伤害加成')
				begin
					update Assemble
					set Assemble.Physics = Assemble.Physics - @mainTagvalue
					where Assemble.Name = @Name;	
				end
			else if(@mainTagname = '暴击率')
				begin
					update Assemble
					set Assemble.Criticalhit = Assemble.Criticalhit - @mainTagvalue
					where Assemble.Name = @Name;	
				end
			else if(@mainTagname = '暴击伤害')
				begin
					update Assemble
					set Assemble.Criticaldamage = Assemble.Criticaldamage - @mainTagvalue
					where Assemble.Name = @Name;	
				end
			else if(@mainTagname = '治疗加成')
				begin
					update Assemble
					set Assemble.Treatment = Assemble.Treatment - @mainTagvalue
					where Assemble.Name = @Name;	
				end

			/*删去副词条属性值*/
			if(@Tagname_1 = '生命值')
				begin
					update Assemble
					set Assemble.IncreaseLife = Assemble.IncreaseLife - @value_1
					where Assemble.Name = @Name;
				end
			else if(@Tagname_2 = '生命值')
				begin
					update Assemble
					set Assemble.IncreaseLife = Assemble.IncreaseLife - @value_2
					where Assemble.Name = @Name;
				end
			else if(@Tagname_3 = '生命值')
				begin
					update Assemble
					set Assemble.IncreaseLife = Assemble.IncreaseLife - @value_3
					where Assemble.Name = @Name;
				end
			else if(@Tagname_4 = '生命值')
				begin
					update Assemble
					set Assemble.IncreaseLife = Assemble.IncreaseLife - @value_4
					where Assemble.Name = @Name;
				end


			if(@Tagname_1 = '生命值百分比')
				begin
					update Assemble
					set Assemble.LifePercentage = Assemble.LifePercentage - @value_1
					where Assemble.Name = @Name;
				end
			else if(@Tagname_2 = '生命值百分比')
				begin
					update Assemble
					set Assemble.LifePercentage = Assemble.LifePercentage - @value_2
					where Assemble.Name = @Name;
				end
			else if(@Tagname_3 = '生命值百分比')
				begin
					update Assemble
					set Assemble.LifePercentage = Assemble.LifePercentage - @value_3
					where Assemble.Name = @Name;
				end
			else if(@Tagname_4 = '生命值百分比')
				begin
					update Assemble
					set Assemble.LifePercentage = Assemble.LifePercentage - @value_4
					where Assemble.Name = @Name;
				end

			if(@Tagname_1 = '攻击力')
				begin
					update Assemble
					set Assemble.IncreaseAttack = Assemble.IncreaseAttack - @value_1
					where Assemble.Name = @Name;
				end
			else if(@Tagname_2 = '攻击力')
				begin
					update Assemble
					set Assemble.IncreaseAttack = Assemble.IncreaseAttack - @value_2
					where Assemble.Name = @Name;
				end
			else if(@Tagname_3 = '攻击力')
				begin
					update Assemble
					set Assemble.IncreaseAttack = Assemble.IncreaseAttack - @value_3
					where Assemble.Name = @Name;
				end
			else if(@Tagname_4 = '攻击力')
				begin
					update Assemble
					set Assemble.IncreaseAttack = Assemble.IncreaseAttack - @value_4
					where Assemble.Name = @Name;
				end

			if(@Tagname_1 = '攻击力百分比')
				begin
					update Assemble
					set Assemble.AttackPercentage = Assemble.AttackPercentage - @value_1
					where Assemble.Name = @Name;
				end
			else if(@Tagname_2 = '攻击力百分比')
				begin
					update Assemble
					set Assemble.AttackPercentage = Assemble.AttackPercentage - @value_2
					where Assemble.Name = @Name;
				end
			else if(@Tagname_3 = '攻击力百分比')
				begin
					update Assemble
					set Assemble.AttackPercentage = Assemble.AttackPercentage - @value_3
					where Assemble.Name = @Name;
				end
			else if(@Tagname_4 = '攻击力百分比')
				begin
					update Assemble
					set Assemble.AttackPercentage = Assemble.AttackPercentage - @value_4
					where Assemble.Name = @Name;
				end

			if(@Tagname_1 = '防御力')
				begin
					update Assemble
					set Assemble.IncreaseDefense = Assemble.IncreaseDefense - @value_1
					where Assemble.Name = @Name;
				end
			else if(@Tagname_2 = '防御力')
				begin
					update Assemble
					set Assemble.IncreaseDefense = Assemble.IncreaseDefense - @value_2
					where Assemble.Name = @Name;
				end
			else if(@Tagname_3 = '防御力')
				begin
					update Assemble
					set Assemble.IncreaseDefense = Assemble.IncreaseDefense - @value_3
					where Assemble.Name = @Name;
				end
			else if(@Tagname_4 = '防御力')
				begin
					update Assemble
					set Assemble.IncreaseDefense = Assemble.IncreaseDefense - @value_4
					where Assemble.Name = @Name;
				end

			if(@Tagname_1 = '防御力百分比')
				begin
					update Assemble
					set Assemble.DefensePercentage = Assemble.DefensePercentage - @value_1
					where Assemble.Name = @Name;
				end
			else if(@Tagname_2 = '防御力百分比')
				begin
					update Assemble
					set Assemble.DefensePercentage = Assemble.DefensePercentage - @value_2
					where Assemble.Name = @Name;
				end
			else if(@Tagname_3 = '防御力百分比')
				begin
					update Assemble
					set Assemble.DefensePercentage = Assemble.DefensePercentage - @value_3
					where Assemble.Name = @Name;
				end
			else if(@Tagname_4 = '防御力百分比')
				begin
					update Assemble
					set Assemble.DefensePercentage = Assemble.DefensePercentage - @value_4
					where Assemble.Name = @Name;
				end

			if(@Tagname_1 = '元素精通')
				begin
					update Assemble
					set Assemble.Mystery = Assemble.Mystery - @value_1
					where Assemble.Name = @Name;
				end
			else if(@Tagname_2 = '元素精通')
				begin
					update Assemble
					set Assemble.Mystery = Assemble.Mystery - @value_2
					where Assemble.Name = @Name;
				end
			else if(@Tagname_3 = '元素精通')
				begin
					update Assemble
					set Assemble.Mystery = Assemble.Mystery - @value_3
					where Assemble.Name = @Name;
				end
			else if(@Tagname_4 = '元素精通')
				begin
					update Assemble
					set Assemble.Mystery = Assemble.Mystery - @value_4
					where Assemble.Name = @Name;
				end

			if(@Tagname_1 = '元素充能效率')
				begin
					update Assemble
					set Assemble.Efficiency= Assemble.Efficiency - @value_1
					where Assemble.Name = @Name;
				end
			else if(@Tagname_2 = '元素充能效率')
				begin
					update Assemble
					set Assemble.Efficiency = Assemble.Efficiency - @value_2
					where Assemble.Name = @Name;
				end
			else if(@Tagname_3 = '元素充能效率')
				begin
					update Assemble
					set Assemble.Efficiency = Assemble.Efficiency - @value_3
					where Assemble.Name = @Name;
				end
			else if(@Tagname_4 = '元素充能效率')
				begin
					update Assemble
					set Assemble.Efficiency = Assemble.Efficiency - @value_4
					where Assemble.Name = @Name;
				end

			if(@Tagname_1 = '暴击率')
				begin
					update Assemble
					set Assemble.Criticalhit = Assemble.Criticalhit - @value_1
					where Assemble.Name = @Name;
				end
			else if(@Tagname_2 = '暴击率')
				begin
					update Assemble
					set Assemble.Criticalhit = Assemble.Criticalhit - @value_2
					where Assemble.Name = @Name;
				end
			else if(@Tagname_3 = '暴击率')
				begin
					update Assemble
					set Assemble.Criticalhit = Assemble.Criticalhit - @value_3
					where Assemble.Name = @Name;
				end
			else if(@Tagname_4 = '暴击率')
				begin
					update Assemble
					set Assemble.Criticalhit = Assemble.Criticalhit - @value_4
					where Assemble.Name = @Name;
				end

			if(@Tagname_1 = '暴击伤害')
				begin
					update Assemble
					set Assemble.Criticaldamage = Assemble.Criticaldamage - @value_1
					where Assemble.Name = @Name;
				end
			else if(@Tagname_2 = '暴击伤害')
				begin
					update Assemble
					set Assemble.Criticaldamage = Assemble.Criticaldamage - @value_2
					where Assemble.Name = @Name;
				end
			else if(@Tagname_3 = '暴击伤害')
				begin
					update Assemble
					set Assemble.Criticaldamage = Assemble.Criticaldamage - @value_3
					where Assemble.Name = @Name;
				end
			else if(@Tagname_4 = '暴击伤害')
				begin
					update Assemble
					set Assemble.Criticaldamage = Assemble.Criticaldamage - @value_4
					where Assemble.Name = @Name;
				end
		end



	

End




GO

ALTER TABLE [dbo].[Assemble] ENABLE TRIGGER [Relics_down]
GO

